home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Trazados, regiones y recorte / Flower / Flower.cs next >
Encoding:
Text File  |  2002-07-15  |  1.8 KB  |  54 lines

  1. //-------------------------------------
  2. // Flower.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class Flower: PrintableForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new Flower());
  14.      }
  15.      public Flower()
  16.      {
  17.           Text = "Flor";
  18.      }
  19.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  20.      {   
  21.                // Dibujar un tallo verde desde la esquina inferior izquierda al centro.
  22.  
  23.           grfx.DrawBezier(new Pen(Color.Green, 10), 
  24.                     new Point(0, cy),          new Point(0, 3 * cy / 4),
  25.                     new Point(cx / 4, cy / 4), new Point(cx / 2, cy / 2));
  26.  
  27.                // Definir la trasnformaci≤n para el resto de la flor.
  28.  
  29.           float fScale = Math.Min(cx, cy) / 2000f;
  30.           grfx.TranslateTransform(cx / 2, cy / 2);
  31.           grfx.ScaleTransform(fScale, fScale);
  32.  
  33.                // Dibujar pΘtalos rojos.
  34.  
  35.           GraphicsPath path = new GraphicsPath();
  36.  
  37.           path.AddBezier(new Point(  0,    0), new Point(125,  125),
  38.                          new Point(475,  125), new Point(600,    0));
  39.           path.AddBezier(new Point(600,    0), new Point(475, -125), 
  40.                          new Point(125, -125), new Point(  0,    0));
  41.  
  42.           for (int i = 0; i < 8; i++)
  43.           {
  44.                grfx.FillPath(Brushes.Red, path);
  45.                grfx.DrawPath(Pens.Black, path);
  46.                grfx.RotateTransform(360 / 8);
  47.           }
  48.                // Dibujar un cφrculo amarillo en el centro.
  49.  
  50.           Rectangle rect = new Rectangle(-150, -150, 300, 300);
  51.           grfx.FillEllipse(Brushes.Yellow, rect);
  52.           grfx.DrawEllipse(Pens.Black, rect);
  53.      }
  54. }